package com.xzh.homeliving.commodity.web;

import com.xzh.homeliving.commodity.entity.CategoryEntity;
import com.xzh.homeliving.commodity.service.CategoryService;
import com.xzh.homeliving.commodity.vo.Catalog2Vo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author: zhiHong
 * @CreateTime: 2024-02-06 20:23
 * @Description: 响应用户首页
 */
@Controller
public class IndexController {
    @Resource
    private CategoryService categoryService;
    /**
     * 响应用户请求首页
     */
    @GetMapping(value = {"/", "/index.html"})
    private String indexPage(Model model) {
        List<CategoryEntity> firstLevelCate = categoryService.getFirstLevelCate();
        model.addAttribute("firstLevelCate", firstLevelCate);
        return "index";
    }

    @GetMapping("/index/catalog.json")
    @ResponseBody
    public Map<String, List<Catalog2Vo>> getCatalogJson() {
        return categoryService.getCatalogJson();
    }
}
